﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MonitorServersWeb;
using System.Drawing;

public partial class Controls_ucServerPerformance : System.Web.UI.UserControl
{
    public ServerInfo serverInfo { set; get; }
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();

    }

    public void LoadData()
    {
        List<ServerMemory> info;
        if ((info = WMIUtil.WMIUtilStatic.GetServerMemory(serverInfo)) != null)
        {
            double r;
            try
            {
                r = ((double)info[0].FreePhysicalMemory / (double)info[0].TotalVisibleMemorySize) * 100;
            }
            catch
            {
                r = 0;
            }

            lblFreeRatio.Text = String.Format("Free Memory: {0:0.00}%", r);

            Chart1.Series.Clear();
            Chart1.Series.Add("Series1");
            Chart1.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie;
            Chart1.Series["Series1"].Points.AddY((double)info[0].FreePhysicalMemory);
            Chart1.Series["Series1"].Points[0].Color = (r > 30 ? Color.Green : Color.Red);
            Chart1.Series["Series1"].Points[0].Label = "Free";
            Chart1.Series["Series1"].Points.AddY((double)info[0].TotalVisibleMemorySize - (double)info[0].FreePhysicalMemory);
            Chart1.Series["Series1"].Points[1].Color = Color.Blue;
            Chart1.Series["Series1"].Points[1].Label = "Used";
        }

    }
}